package com.cardbaobao.cardbabyclient.ui.pop;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.cardbaobao.cardbabyclient.R;

/**
 * Created by FHW
 * on 2017/11/8 9:58.
 */

public class RepayNumberKeyBoardPop extends PopupWindow {
    private OnKeyPressed listener;

    public RepayNumberKeyBoardPop(Context context) {
        View root = LayoutInflater.from(context).inflate(R.layout.pop_number_keyboard_repay, null);
        setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
//        setHeight(WindowManager.LayoutParams.MATCH_PARENT);
        //设置透明背景
        setBackgroundDrawable(new ColorDrawable(0x00FFFFFF));
        setOutsideTouchable(true);
        root.findViewById(R.id.ibt_hide_keyboard).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        root.findViewById(R.id.key_delete).setOnClickListener(clickListener);
        root.findViewById(R.id.key_one).setOnClickListener(clickListener);
        root.findViewById(R.id.key_two).setOnClickListener(clickListener);
        root.findViewById(R.id.key_three).setOnClickListener(clickListener);
        root.findViewById(R.id.key_four).setOnClickListener(clickListener);
        root.findViewById(R.id.key_five).setOnClickListener(clickListener);
        root.findViewById(R.id.key_six).setOnClickListener(clickListener);
        root.findViewById(R.id.key_seven).setOnClickListener(clickListener);
        root.findViewById(R.id.key_eight).setOnClickListener(clickListener);
        root.findViewById(R.id.key_nine).setOnClickListener(clickListener);
        root.findViewById(R.id.key_zero).setOnClickListener(clickListener);
        root.findViewById(R.id.key_dot).setOnClickListener(clickListener);
        root.findViewById(R.id.key_debit).setOnClickListener(clickListener);
//        root.findViewById(R.id.rl_bg).setOnClickListener(clickListener);
        setAnimationStyle(R.style.CustomBottomAnimateStyle);
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        setContentView(root);
    }

    private View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (listener != null) {
                switch (v.getId()) {
                    case R.id.key_delete:
                        listener.onKeyPressed(OnKeyPressed.KEY_DELETE);
                        break;
                    case R.id.key_one:
                        listener.onKeyPressed(OnKeyPressed.KEY_ONE);
                        break;
                    case R.id.key_two:
                        listener.onKeyPressed(OnKeyPressed.KEY_TWO);
                        break;
                    case R.id.key_three:
                        listener.onKeyPressed(OnKeyPressed.KEY_THREE);
                        break;
                    case R.id.key_four:
                        listener.onKeyPressed(OnKeyPressed.KEY_FOUR);
                        break;
                    case R.id.key_five:
                        listener.onKeyPressed(OnKeyPressed.KEY_FIVE);
                        break;
                    case R.id.key_six:
                        listener.onKeyPressed(OnKeyPressed.KEY_SIX);
                        break;
                    case R.id.key_seven:
                        listener.onKeyPressed(OnKeyPressed.KEY_SEVEN);
                        break;
                    case R.id.key_eight:
                        listener.onKeyPressed(OnKeyPressed.KEY_EIGHT);
                        break;
                    case R.id.key_nine:
                        listener.onKeyPressed(OnKeyPressed.KEY_NINE);
                        break;
                    case R.id.key_zero:
                        listener.onKeyPressed(OnKeyPressed.KEY_ZERO);
                        break;
                    case R.id.key_dot:
                        listener.onKeyPressed(OnKeyPressed.KEY_DOT);
                        break;
                    case R.id.key_debit:
                        listener.onKeyPressed(OnKeyPressed.KEY_FINISH);
                        break;
//                    case R.id.rl_bg:
//                        dismiss();
//                        break;
                }
            }
        }
    };


    public void setNumberKeyListener(OnKeyPressed listener) {
        this.listener = listener;
    }

    public interface OnKeyPressed {
        int KEY_FINISH = -2;//完成[付款]
        int KEY_DELETE = -1;//删除
        int KEY_ZERO = 0;//0
        int KEY_ONE = 1;//1
        int KEY_TWO = 2;//2
        int KEY_THREE = 3;//3
        int KEY_FOUR = 4;//4
        int KEY_FIVE = 5;//5
        int KEY_SIX = 6;//6
        int KEY_SEVEN = 7;//7
        int KEY_EIGHT = 8;//8
        int KEY_NINE = 9;//9
        int KEY_DOT = 10;//.

        void onKeyPressed(int key);
    }
}
